#include "Word.h"

struct _WORD * Word_Create()
{
	struct _WORD * W;
	W = (struct _WORD *)malloc(sizeof(struct _WORD));
	W->K = (rand() % 50) + 1;
	W->D = Buffer_Create(0);
	W->Encrypted = FALSE;
	return W;
}

void Word_Clear(struct _WORD * W)
{
	Buffer_Clear(W->D);
	W = Word_Create();
}

BOOLEAN Word_Encrypt(struct _WORD * W)
{
	int i = 0,c = 0;
	if(!W->Encrypted)
	{
		for(;W->D->Data[c][i];++i)
		{
			W->D->Data[c][i] += W->K;
			ITT_CHUNK_CHECK(i,c);
		}
		W->Encrypted = TRUE;
	}
	return TRUE;
}

BOOLEAN Word_Decrypt(struct _WORD * W)
{
	int i = 0,c = 0;
	if(W->Encrypted)
	{
		for(;W->D->Data[c][i];++i)
		{
			W->D->Data[c][i] -= W->K;
			ITT_CHUNK_CHECK(i,c);
		}
		W->Encrypted = FALSE;
	}
	return TRUE;
}